<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Index_Shop extends Controller_Index_Base
{ 
    public function action_index()
    {
        $url  = $this->request->param('shop') ? $this->request->param('shop') : null;
        $shop = ORM::factory('shop')->get_shop_by_url($url);
   
        $coupons = ORM::factory('coupon')->get_coupons($shop);       
        
        $content = new View('index/shop/index_tpl');
        $content->shop    = $shop; 
        $content->coupons = $coupons;
        $content->actions = ORM::factory('action')->get_actions($shop);       

        $title       = 'Кэшбэк, купоны и промокоды '.$shop->name.' на StyleGarderob';
        $description = 'Воспользуйтесь кэшбэком, бесплатными купонами и промокодами '.$shop->name.', чтобы сэкономить';
        $this->print_template($title, $content, $description); 
    }
   
    public function action_all()
    {
        $content = new View('index/shop/all_tpl');
        $content->shops = ORM::factory('shop')->get_all_shops(); 

        $this->print_template('Все магазины, промокоды и кэшбэк к ним на StyleGarderob', $content);  
    }
    
    public function action_go()
    {
        $shop_id = $this->request->param('shop_id') ? $this->request->param('shop_id') : 0;
        $shop    = ORM::factory('shop', $shop_id);
        
        ORM::factory('click')->add_click_if_cashback_available($shop);
        
        $content = new View('index/shop/go_tpl');
        $content->title   = 'Осуществляется переход...';
        $content->shop    = $shop;
        $content->delay   = 2;       
        $this->response->body($content);
    }
} 
